﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WebSite.Models.PayModel>" %>
<%@ Import Namespace="WebSite.Models" %>
<%@ Import Namespace="WebSite.App_Code" %>
<%@ Import Namespace="WebSite.App_Data" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Pay
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <link href="../../Scripts/jquery-ui/css/redmond/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" />
    <script type="text/javascript" src="../../Scripts/external/jquery.bgiframe-2.1.2.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery-ui-dialog/jquery.ui.core.js"></script>
	<script type="text/javascript" src="../../Scripts/jquery-ui-dialog/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="../../Scripts/jquery-ui-dialog/jquery.ui.position.js"></script>
	<script type="text/javascript" src="../../Scripts/jquery-ui-dialog/jquery.ui.dialog.js"></script>
    
    <script type="text/javascript" src="../../Scripts/jquery-pending/jquery-pending.js"></script>

    <script language="javascript" src="../../Scripts/jqprint/jquery.jqprint.js"></script>

    <style type="text/css">
    
    .List
    {
         background-color:White;
    }
     
    .List .header td
    {
        border:2px solid #385D8A;
        border-left:none;
        white-space:nowrap;
        padding:5px;
        background-color:#4F81BD;
        color:White;
    }
    
    .List .body td
    {
        border:2px solid #385D8A;
        border-top:none;
        border-left:none;
        white-space:nowrap;
        padding:5px;
    }
    
    .List .header .first
    {
        border-left:2px solid #385D8A;
        white-space:nowrap;
        padding:5px;
    }
    
    .List .header .hiden
    {
        background-color:#595959;
    }
    
    .List .body .first
    {
        border-left:2px solid #385D8A;
        border-right:none;
        white-space:nowrap;
        padding:5px;
    }
    
    .List .body .left_half
    {
        border-right:none;
        white-space:nowrap;
        padding:5px;
    }
    
    .List .header .blank, .List .body .blank
    {
        background-color:#D8E5D3;
        border-top:none;
        border-bottom:none;
    }
    
    .List .header .warning
    {
        background-color:#C0504D;
    }
    
    .SelectTB
    {
        
    }
    
     .SelectTB .Normal
     {
         cursor:pointer;
         text-decoration:none;
         width:300px;
         display:block;
         padding:2px
     }
     
      .SelectTB .Selected
     {
         color:Red;
         font-weight:bold;
         cursor:pointer;
         text-decoration:none;
         width:300px;
         display:block;
         padding:2px
     }
     
     .SelectTB .Normal:hover
     {
         background-color:#385D8A;
         color:#FFFFFF;
     }
     
     .SelectTB .Selected:hover
     {
         background-color:#385D8A;
     }
     
     .SelectTB .Normal:focus
     {
         outline:none;
     }
     
     .SelectTB .Selected:focus
     {
         outline:none;
     }
    
    </style>
    
    <script type="text/javascript">

        $(document).ready(function () {
        
        });

        function Pending(on_off) {

            if (on_off) {

                $("#dialog-Wait").pending({
                    height: 30,
                    width: 24,
                    modal: true
                });
            }
            else {

                $("#dialog-Wait").pending(false);
            }
        }

        function openAccountCodeSelect() {

            $(function () {
                $("#dialog-AccountCode").dialog({
                    height: 400,
                    width: 320,
                    modal: true
                });
            });
        }

        function Posting(event, id) { $("#PostingEvent").val(event); $("#PostingID").val(id); }

        function OnAddItem() { Pending(true); Posting('<%=L_PageEvent.P_PaySubmit_AddItem %>', null); }

        function OnDeleteItem(rid) {
            if (confirm("确定要删除该行吗？")) {
                Pending(true);
                Posting('<%=L_PageEvent.P_PaySubmit_DeleteItem %>', rid);
                return true;
            }
            else {
                return false;
            } 
        }

        function OnSave() { Pending(true); 
        Posting('<%=L_PageEvent.P_PaySubmit_Save %>', null); }

        function OnSubmit() { Pending(true); Posting('<%=L_PageEvent.P_PaySubmit_Submit %>', null); }

        function OnPrint() { Pending(true); Posting('<%=L_PageEvent.P_PaySubmit_Print %>', null); }

        function SelAC(img, row) {

            openAccountCodeSelect();

            $("#dialog-AccountCode").attr("handler", row);

            var ac_type = $("input:eq(1)", $(img).parent().prev()).val();
            var ac_id = $("input:eq(2)", $(img).parent().prev()).val();

            $("a", $("#dialog-AccountCode")).attr("class", "Normal");
            $("a[ac_type=" + ac_type + "][ac_id=" + ac_id + "]", $("#dialog-AccountCode")).attr("class", "Selected");
            $("a[ac_type=" + ac_type + "][ac_id=" + ac_id + "]", $("#dialog-AccountCode")).focus();
        }

        function SelOneAC(sender) {
        
            var ac_type = $(sender).attr("ac_type");
            var ac_id = $(sender).attr("ac_id");
            var ac_show = $(sender).attr("ac_show");
            
            var handler = $("#DetailTB tr:eq(" + $("#dialog-AccountCode").attr("handler") + ") td:eq(0)");

            $("input:eq(0)", handler).val(ac_show);
            $("input:eq(1)", handler).val(ac_type);
            $("input:eq(2)", handler).val(ac_id);

            $("#dialog-AccountCode").dialog("close");
        }

        function SelDep(dep) {
            var dep_id = $(dep).val();
            
            $("a[ac_type=<%=((int)L_AccountType.Budget).ToString() %>]", $("#dialog-AccountCode")).hide();
            $("a[ac_type=<%=((int)L_AccountType.Budget).ToString() %>][dep_id=" + dep_id + "]", $("#dialog-AccountCode")).show();
        }

        function AccountShow_On_KeyPress(sender, e) {

            if (e.keyCode == 13) {
                
                CheckAC(sender)
                
                return false;
            }
        }

        function AccountShow_On_Blur(sender) {
            CheckAC(sender)
        }

        function CheckAC(sender) {
            var txt = $(sender).val();

            if ($.trim(txt) == "") {return true; }

            var Q = $("a[ac_type=<%=((int)L_AccountType.Asset).ToString() %>][ac_id=" + txt + "]", $("#dialog-AccountCode"));

            if (Q.length > 0) {
                $(sender).val(Q.attr("ac_show"));
                return true;
            }

            Q = $("a[ac_type=<%=((int)L_AccountType.Asset).ToString() %>][ac_show=" + txt + "]", $("#dialog-AccountCode"));

            if (Q.length > 0) { return true; }

            Q = $("a[ac_type=<%=((int)L_AccountType.Budget).ToString() %>][ac_id=" + txt + "]", $("#dialog-AccountCode"));

            if (Q.length > 0) { return true; }

            alert("该代码不存在，请选择有效的编码");
            return false
        }

        function SelAC_Detail(img, row) {
            
            var tr = $(img).parents("tr:eq(0)");

            var ac_id = $("td input:eq(2)", tr).val();

            if(ac_id == "") {
                alert("请选择一级科目");
            }
            else {
                Posting('<%=L_PageEvent.P_PaySubmit_SelAccountCodeDetail %>', row);
                $("form").submit();
            }
        }

    </script>

    <script type="text/javascript">
        $(document).ready(function () {
            $("#print").click(function () {
                $(".my_show").jqprint();
            })
        }); 
    </script> 

    <%--<div class="my_show">这个打印时是显示的</div> 
    <div class="my_hidden">这个打印时是隐藏的。</div> 
    <input type="button" id="print"/> --%>

    <% Html.BeginForm(); %>
    
    <%=Html.HiddenFor(o => o.PostingEvent, new { id = "PostingEvent" })%>
    <%=Html.HiddenFor(o => o.PostingID, new { id = "PostingID" })%>
    <%=Html.HiddenFor(m => m.DS_Pay.Guid) %>
    
    <table cellpadding="0" cellspacing="10" border="0">
        <tr>
            <td colspan="6" align="center">
                <b style="font-size:x-large">经费审核结算单</b></td>
            <td align="right">编号</td>
            <td><%=Html.TextBoxFor(m => m.DS_Pay.SN, new { @class = "budget-txt-no-01" })%></td>
        </tr>
        <tr>
            <td align="right">填制单位：</td>
            <td>海军医学研究所</td>
            <td colspan="4"></td>
            <td align="right">第</td>
            <td>
                <%=Html.TextBox("A","", new { @class = "budget-txt-no-01", style="width:20px" })%>
                &nbsp;/&nbsp;
                <%=Html.TextBox("B", "", new { @class = "budget-txt-no-01", style = "width:20px" })%></td>
        </tr>
        <tr>
            <td align="right" style="width:70px">结算单位：</td>
            <td><%=Html.DropDownListFor(m => m.DS_Pay.DepartmentGuid, Model.DS_Department, new { style = "width:150px", onchange= "SelDep(this)" })%></td>
            <td align="right" style="width:70px">单据张数：</td>
            <td><%=Html.TextBoxFor(m => m.DS_Pay.BillNum, new { @class = "budget-txt-no-01", style = "width:50px" })%></td>
            <td align="right" style="width:70px">附件：</td>
            <td><%=Html.TextBoxFor(m => m.DS_Pay.AttachmentNum, new { @class = "budget-txt-no-01", style = "width:50px" })%></td>
            <td align="right" style="width:70px">结算日期：</td>
            <td><%=Html.TextBoxFor(m => m.DS_Pay.PayDate, new { @class = "budget-txt-no-01", style = "width:80px" })%></td>
        </tr>
    </table>

    <table border="0" cellpadding="0" cellspacing="0" class="List" id="DetailTB">
        <tr class="header">
            <td class="first" colspan="2">一级科目</td>
			<td colspan="2">明细科目</td>
			<td>内容摘要</td>	
			<td>借贷</td>
            <td>金额</td>
            <td>&nbsp;</td>
        </tr>        
        <% for (int i = 0; i < Model.DS_PayDetail.Count; i++) { %>
            <tr class="body">
                <td class="first" valign="top">
                    <%=Html.TextBoxFor(m => m.DS_PayDetail[i].AccountShow, new { @class = "budget-txt-no-01", style = "width:80px", autocomplete = "off", onkeypress = "return AccountShow_On_KeyPress(this,event)", onblur = "AccountShow_On_Blur(this)" })%>
                    <%=Html.HiddenFor(m=>m.DS_PayDetail[i].Detail.AccountType) %>
                    <%=Html.HiddenFor(m=>m.DS_PayDetail[i].Detail.AccountCode) %>
                </td>
                <td valign="top">
                    <img src="../../Style/Img/search.png" style=" cursor:pointer" onclick="SelAC(this, <%=i+1 %>)" />
                </td>
			    <td class="left_half" valign="top"><%=Html.TextBoxFor(m => m.DS_PayDetail[i].Detail.AccountDetail, new { @class = "budget-txt-no-01", style = "width:170px", autocomplete = "off" })%></td>
			    <td valign="top">
                    <img src="../../Style/Img/search.png" style=" cursor:pointer" onclick="SelAC_Detail(this, <%=i %>)" />
                </td>
                <td><%=Html.TextAreaFor(m => m.DS_PayDetail[i].Detail.Comment, new { @class = "budget-txt-no-01", style = "width:275px; height:40px", autocomplete = "off" })%></td>	
			    <td valign="top"><%=Html.DropDownListFor(m=>m.DS_PayDetail[i].Detail.PayType, Model.DS_PayType) %></td>
                <td valign="top"><%=Html.TextBoxFor(m => m.DS_PayDetail[i].Detail.Amount, new { @class = "budget-txt-no-01", style = "width:100px", autocomplete = "off" })%></td>
                <td valign="top">
                    <% if ((i + 1) == Model.DS_PayDetail.Count) { %>
                        <input type="submit" value="添加" onclick="OnAddItem()" class="budget-button-no-01"/>
                    <%} else { %>
                        <input type="submit" value="删除" onclick="return OnDeleteItem('<%=i %>')" class="budget-button-no-01"/>
                    <% } %>
                </td>
            </tr>        
        <% } %>
    </table>

    <br />

    <table>
        <tr>
            <td align="right">现金付</td>
            <td><input class = "budget-txt-no-01"/></td>
            <td align="right">银行付</td>
            <td><input class = "budget-txt-no-01"/></td>
            <td align="right">转账</td>
            <td><input class = "budget-txt-no-01"/></td>
            <td align="right">POS</td>
            <td><input class = "budget-txt-no-01"/></td>
        </tr>
        <tr>
            <td align="right">还款 现:</td>
            <td><input class = "budget-txt-no-01"/></td>
            <td align="right">银:</td>
            <td><input class = "budget-txt-no-01"/></td>
            <td align="right">收款 现:</td>
            <td><input class = "budget-txt-no-01"/></td>
            <td align="right">银:</td>
            <td><input class = "budget-txt-no-01"/></td>
        </tr>
        <tr>
            <td  align="right" valign="top">备注</td>
            <td colspan="7">
                <%=Html.TextAreaFor(m => m.DS_Pay.Rem, new { @class = "budget-txt-no-01",style="height:50px; width:700px" } )%></td>
        </tr>
    </table>

    <br />
    <% if (String.IsNullOrEmpty(Model.DS_Pay.PayStatus) || Model.DS_Pay.PayStatus == ((int)L_PayStatus.Save).ToString()) { %>
        <input type="submit" value="保存" class="budget-button-no-01" onclick="OnSave()" />
        <input type="submit" value="提交" class="budget-button-no-01" onclick="OnSubmit()" />    
    <% } else { %>
        <input type="submit" value="打印" class="budget-button-no-01" onclick="OnPrint()" />
    <% } %>
    

    <% Html.EndForm(); %>

    <div id="dialog-Wait" style=" text-align:center; padding:0px; display:none; overflow:hidden">
		<img src="../../Style/Img/loading-01.GIF" />
	</div>

    <div id="dialog-AccountCode" style=" text-align:center; padding:0px; display:none; overflow:hidden" handler="">
        <div style="  height:300px;text-align:left; padding:10px">
            预算<br /><br />
            <div style=" overflow-y:auto;overflow-x:hidden; border:1px solid black; height:180px; width:300px; ">
		        <table class="SelectTB" width="300" cellpadding="0" border="0" cellspacing="0">                
                    <% foreach (vw_Budget B in Model.DS_AC_Budget) { %>
                        <tr>
                            <td align="left" style="padding:0px" >                                
                                <a ac_type="<%=((int)L_AccountType.Budget).ToString() %>"  
                                    ac_id="<%=B.ProjectCode %>" 
                                    ac_show="<%=B.ProjectCode %>" 
                                    dep_id="<%=B.DepartmentID %>"
                                    onclick="SelOneAC(this)" href="javascript:void(0)"
                                    <%if (B.DepartmentID != this.Model.DS_Pay.DepartmentGuid) { %>style="display:none"<%} %> >
                                    &nbsp;&nbsp;—&nbsp;&nbsp;<%=B.ProjectCode %>&nbsp;&nbsp;<%=B.ProjectName %>
                                </a>
                            </td>
                        </tr>                
                    <% } %>
                </table>
            </div><br />
            资产<br /><br />
            <div style=" overflow-y:auto;overflow-x:hidden; border:1px solid black; height:80px; width:300px; ">
		        <table class="SelectTB" width="300" cellpadding="0" border="0" cellspacing="0">
                    <% foreach (md_AssetSubject B in Model.DS_AC_Asset) { %>
                        <tr>
                            <td align="left" style="padding:0px">
                                <a ac_type="<%=((int)L_AccountType.Asset).ToString() %>" 
                                    ac_id="<%=B.No %>" 
                                    ac_show="<%=B.Name %>" 
                                    onclick="SelOneAC(this)" href="javascript:void(0)">
                                    &nbsp;&nbsp;—&nbsp;&nbsp;<%=B.No %>&nbsp;&nbsp;<%=B.Name %>
                                </a>
                            </td>
                        </tr>                
                    <% } %>
                </table>
            </div>
        </div>
	</div>

    <%Html.RenderPartial("SelAccountDetail", Model.CM_SAD); %>

    <br />
    <div style="color:Red; font-weight:bold"><%=ViewData["DB.Operation.Result"]%></div>

</asp:Content>
